<?php
$mypage = 'rex_lang';
$backupFile = $REX['INCLUDE_PATH'] . "/addons/" . $mypage .'/backup/tablebackup.sql';
@chmod($REX['INCLUDE_PATH'] . "/addons/" . $mypage .'/backup',0666);
$error = '';
if (!OOAddon :: isAvailable('addon_framework'))
{
  $error .= 'Required addon "addon_framework" is either not installed or not activated!';
}

if ($error == '') {
   $qry[] = "CREATE TABLE IF NOT EXISTS `rex_393_domain` (
  `id` int(11) NOT NULL auto_increment,
  `domain` varchar(254) default NULL,
  `is_main` tinyint(1) default '0',
  `language` int(11) default NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `domain` (`domain`),
  KEY `language` (`language`)
)";   
   $qry[] = "CREATE TABLE IF NOT EXISTS `rex_393_language` (
  `id` int(11) NOT NULL default '0',
  `status` tinyint(1) NOT NULL default '0',
  `xtcommerce_id` int(11) default NULL,
  `xtcommerce_folder` varchar(55) default NULL,
  `lang_icon` varchar(128) default NULL,
  `lang_icon_over` varchar(128) default NULL,
  `meta_language` varchar(35) default NULL,
  `priority` int(11) default NULL,
  PRIMARY KEY  (`id`)
)";   
   $sql = new rex_sql();
   foreach ($qry as $myQry)
   	if($sql->setQuery($myQry)==0)
   		$error .="error on creating tables";	

  if ($error == '' && is_file($backupFile)) {
  	$filecontent = rex_get_file_contents($backupFile);
	$filecontent = split("\n",$filecontent);   
	foreach ($filecontent as $qry) {
		if ($qry)	
			$sql->setQuery($qry);
	}
  } elseif ($error == '') {
  
	foreach ($REX['CLANG'] as $key => $value) {
		$status = $key==0 ? 1 : 0;
		$sql->setQuery("insert into rex_393_language (`id`,`priority`,`meta_language`,`status`) VALUES (" . $key . "," . $key . ",'please change'," . $status . ");");	
		$domain = $key==0 ? $REX['SERVER'] : $value . 'pleasechange.com';
		$sql->setQuery("insert into rex_393_domain (`domain`,`is_main`,`language`) values ('" . $domain . "',1," . $key . ");");			
	}
  
  }
}
if($error=='')
	$REX['ADDON']['install'][$mypage] = 1;
else
	echo $error;
?>

